package org.mpd.amobilempd.network;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

public class MPDConnection {
	// Connection attributes
	String hostname,password;
	int port;
	
	private static final int TIMEOUT = 15000;
	
	Socket connectionsocket;
	
	
	
	public void setPort(int port) {
		if(port >0&&port<=65536){
			this.port = port;
		}
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public void setHostname(String hostname) {
		this.hostname = hostname;
	}
	
	public void openConnection() {
		// TODO
		if(!connectionsocket.isConnected()) {
			SocketAddress address = new InetSocketAddress(hostname,port);
			try {
				connectionsocket.connect(address, TIMEOUT);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public boolean isConnected() {
		// TODO
		return false;
	}
	
	public void closeConnection() {
		// TODO
		if(isConnected()) {
			try {
				connectionsocket.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	
}
